package com.zhuiyun.project.api.weightchangetable.service.impl;

import com.zhuiyun.project.api.weightchangetable.mapper.WeightChangeTableMapper;
import com.zhuiyun.project.api.weightchangetable.model.SelectUserChangeBmiModel;
import com.zhuiyun.project.api.weightchangetable.model.SelectUserWeightChangeTableModel;
import com.zhuiyun.project.api.weightchangetable.service.WeightChangeTableService;
import com.zhuiyun.project.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName WeightChangeTableServiceImpl
 * @Description TODO
 * @Author wuwan
 * @Date 2023/11/29 13:08
 **/
@Service
public class WeightChangeTableServiceImpl implements WeightChangeTableService {
    @Autowired
    WeightChangeTableMapper weightChangeTableMapper;
    @Override
    public CommonResult selectUserWeightChangeTable(Integer uid) {
        List<SelectUserWeightChangeTableModel> selectUserWeightChangeTableModels = weightChangeTableMapper.selectUserWeightChangeTable(uid);
        for (int i = 0; i < selectUserWeightChangeTableModels.size(); i++) {
            SelectUserWeightChangeTableModel selectUserWeightChangeTableModel = selectUserWeightChangeTableModels.get(i);
            Double chronicleWeight = selectUserWeightChangeTableModel.getChronicleWeight();
            Double lastWeight = selectUserWeightChangeTableModel.getLastWeight();
            if (chronicleWeight>lastWeight) {
                double v = chronicleWeight - lastWeight;
                String s = "+" + v;
                selectUserWeightChangeTableModel.setChangeWeight(s);
            }else {
                double v = lastWeight - chronicleWeight;
                String s = "-" + v;
                selectUserWeightChangeTableModel.setChangeWeight(s);
            }
            Date createTime = selectUserWeightChangeTableModel.getCreateTime();
            SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
            String monthAndDay = sdf.format(createTime);
            selectUserWeightChangeTableModel.setMonthAndDayTime(monthAndDay);
        }
        return CommonResult.ok(selectUserWeightChangeTableModels);
    }
    /*
    * @Author wuwan
    * @Description 查询用户最新体脂率 BMI 体重
    * @Date 2023/11/29 14:00
    * @Return
    */
    @Override
    public CommonResult selectUserChangeBmi(Integer uid) {
        SelectUserChangeBmiModel selectUserChangeBmiModel = weightChangeTableMapper.selectUserChangeBmi(uid);


        return CommonResult.ok();
    }
}
